# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1232
# Description:
# Author:       yzl
# Date:         2019-02-09
#-------------------------------------------------------------------------------

from heapq import *
from random import *

data = [1,2,3,4,5,6,7,8,9]

heap = []

for n in data:
    # 随机选择列表数据
    value = choice(data)
    heappush(heap,value)

print(heap)

# 将数据添加到堆
# heappush(heap,2.0)
# print(heap)

# 把列表转化为堆
data1 = [13,22,34,56,90]
# heapify(data1)
# print(data1)

# 弹出最小,压入 200
heapreplace(data1,200)
print(data1)

# 弹出前3个最大值
print(nlargest(2,data1))

# 得到 3 个最小值
print(nsmallest(3,data1))

# 合并多个列表,得到一个新的有序列表
print(list(merge([1,22,45,98],[3,2,7],[90,7])))

# 合并,指定key
print(list(merge(['ss','dd','hh'],['ee','gg'],key=len)))

